import { MutationTree } from "vuex";
import {
    INCREMENT,
    DECREMENT,
    GET_CITY_LIST,
    LOADINF_SHOW,
    CHANGE_OPEN_STATE,
    USER_INFO,
    SET_TOKEN
} from "@/store/types";

const mutations: MutationTree<any> = {
    [INCREMENT](state, payload: number) {
        state.count += payload;
    },
    [DECREMENT](state, payload: number) {
        state.count -= payload;
    },
    //基础知识--将数组转换成前端易解析json对象
    [GET_CITY_LIST](state, payload) {
        state.cityList = payload;
    },
    //公共loading
    [LOADINF_SHOW](state, payload) {
        state.commLoading = payload;
    },
    //立即开通
    [CHANGE_OPEN_STATE](state, payload) {
        state.isOpen = payload;
    },
    //用户头像信息
    [USER_INFO](state, payload) {
        state.username = payload.username || "";
        state.avatar = payload.avatar || "";
        state.permissions = payload.permissions || [];
        state.menus = payload.menus || [];
    },
    //token
    [SET_TOKEN](state, payload) {
        state.token = payload || "";
    }
};

export default mutations;
